package com.zeny.xdclass.common;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @ClassName ResponseResult
 * @Description 自定义响应类
 * @Author zeny
 * @Version 1.0
 */
@Data
@Api(tags = "响应体")
public class ResponseResult {

    @ApiModelProperty(value = "返回状态 true: 执行成功 false: 执行失败 ")
    private Boolean success;
    @ApiModelProperty(value = "20000, 操作成功; 20001, 操作失败;20002, 程序出现了异常; 30000, 没有操作权限")
    private Integer code;
    @ApiModelProperty(value = "消息")
    private String message;
    @ApiModelProperty(value = "数据")
    private Object data;

    public ResponseResult() {
    }

    public ResponseResult(ResultCode resultCode) {
        this.success = resultCode.getSuccess();
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    public static ResponseResult ok() {
        ResponseResult responseResult = new ResponseResult(ResultCode.SUCCESS);
        return responseResult;
    }

    public static ResponseResult fail() {
     ResponseResult responseResult = new ResponseResult(ResultCode.ERROR);
        return responseResult;
    }

    public static ResponseResult auth() {
        ResponseResult responseResult = new ResponseResult(ResultCode.AUTH);
        return responseResult;
    }

    public static ResponseResult exception() {
        ResponseResult responseResult = new ResponseResult(ResultCode.EXCEPTION);
        return responseResult;
    }

    public ResponseResult data(Object data) {
        this.data = data;
        return this;
    }

    public ResponseResult message(String message) {
        this.message = message;
        return this;
    }

    public ResponseResult code(Integer code) {
        this.code = code;
        return this;
    }
}
